﻿using Pdoxcl2Sharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace V3MainTool.Model
{
    /// <summary>
    /// 科技
    /// </summary>
    public partial class V_Tech : IParadoxRead, IParadoxWrite
    {
        public string Name { get; set; }
        public double Tax { get; set; }
        public IList<string> Cores { get; set; }
        public IList<Army> Armies { get; set; }

        public V_Tech()
        {
            Cores = new List<string>();
            Armies = new List<Army>();
        }

        public void TokenCallback(ParadoxParser parser, string token)
        {
            switch (token)
            {
                case "name": Name = parser.ReadString(); break;
                case "tax": Tax = parser.ReadDouble(); break;
                case "add_core": Cores.Add(parser.ReadString()); break;
                case "top_provinces": TopProvinces = parser.ReadStringList(); break;
                case "army": Armies.Add(parser.Parse(new Army())); break;
            }
        }

        public void Write(ParadoxStreamWriter writer)
        {
            if (Name != null)
            {
                writer.WriteLine("name", Name, ValueWrite.Quoted);
            }
            writer.WriteLine("tax", Tax);
            foreach (var val in Cores)
            {
                writer.WriteLine("add_core", val);
            }
            if (TopProvinces != null)
            {
                writer.Write("top_provinces={ ");
                foreach (var val in TopProvinces)
                {
                    writer.Write(val, ValueWrite.Quoted);
                    writer.Write(" ");
                }
                writer.WriteLine("}");
            }
            foreach (var val in Armies)
            {
                writer.Write("army", val);
            }
        }
    }
}
